<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h2>总数：{{total}}</h2>
        <my-btn @increase='getTotal' @reduce="getTotal"></my-btn>
    </div>
    <template id="temp">
        <div>
            <button @click="add()">单击+1</button>
            <button @click="red()">单击-1</button>
        </div>
    </template>
    <script type="text/javaScript"  charset="UTF-8" src="/JS文件/vue.js"></script>
    <script>
       Vue.component('my-btn',{
           template:'#temp',
           data(){
               return{
                   counter:0
               }
           },
           methods:{
               add(){
                   this.counter++;
                   this.$emit('increase',this.counter);
               },
               red(){
                   this.counter--;
                   this.$emit('reduce',this.counter);
               }
           }
       })
       var vm = new Vue({
           el:'#app',
           data:{
               total:0
           },
           methods:{
               getTotal(to){
                   this.total=to;
               }
           }
       })
    </script>
</body>
</html>